package com.you.bio.fileio;

import com.you.bio.constant.Constants;

import java.io.*;

public class BufferedIODemo {

    public static void main(String[] args) throws Exception {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(Constants.INPUT_FILE_PATH)));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(Constants.OUTPUT_FILE_PATH)));
        int len = 0;
        byte[] buf = new byte[100];
        while ((len = bis.read(buf)) != -1) {
            System.out.print(new String(buf, 0, len));
            bos.write(buf, 0, len); //未达到BufferedOutputStream缓存区大小，不会刷缓存区，即此时可能不写文件
            //bos.flush();
        }
        System.out.println("---------------开始写文件-----------------");
        Thread.sleep(20000L);
        bos.flush(); //调用flush方法，会强制刷缓存区，将数据从BufferedOutputStream的缓冲区数据复制内核缓冲区,
        //bos.close(); //调用close方法，会强制刷缓存区，将数据从BufferedOutputStream的缓冲区数据复制内核缓冲区,
    }
}
